<template>
    <el-card>
      <h2>当前天气</h2>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-card>
            <h3>温度</h3>
            <p>{{ weather.temperature }}°C</p>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card>
            <h3>湿度</h3>
            <p>{{ weather.humidity }}</p>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card>
            <h3>风速</h3>
            <p>{{ weather.wind_speed }}</p>
          </el-card>
        </el-col>
      </el-row>
      <h2>未来15天天气</h2>
      <el-table :data="forecast" style="width: 100%">
        <el-table-column prop="date" label="日期" />
        <el-table-column prop="temperature" label="温度" />
        <el-table-column prop="weather" label="天气" />
      </el-table>
    </el-card>
  </template>
  
  <script>
  export default {
    computed: {
      weather() {
        return this.$store.state.currentWeather
      },
      forecast() {
        return this.$store.state.forecast
      }
    },
    created() {
      this.$store.dispatch('fetchCurrentWeather')
      this.$store.dispatch('fetchForecast')
    }
  }
  </script>